﻿using FySystem.Data.OrmA.Attributes;
using FySystem.Data.OrmA.Reflection;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;

namespace FySystem.Data.OrmA.Formatter
{
    interface ISqlFormatter
    {
        /// <summary>
        /// 数据库类型
        /// </summary>
        internal DbTypes DbType { get; }

        /// <summary>
        /// 参数前缀符号
        /// </summary>
        internal string ParameterMark { get; }

        /// <summary>
        /// 关键字符号，这个预留，现在不确定会不会影响效率，也不确定每种数据库的符号是否正确
        /// </summary>
        internal string[] KeywordsMark { get; }

        /// <summary>
        /// 根据不同的数据库，对字段进行大小写转换，这一步其实不做也基本没什么影响
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        internal string FormatFields(string value);

        /// <summary>
        /// 插入数据到数据库时，前置主键获取SQL
        /// </summary>
        /// <param name="fyPrimaryKey"></param>
        /// <returns></returns>
        internal string GetPrePKSQL(FyPrimaryKeyAttribute fyPrimaryKey);

        /// <summary>
        /// 插入数据到数据库时，如果支持同时返回主键，获取返回主键部分的SQL
        /// </summary>
        /// <param name="fyPrimaryKey"></param>
        /// <returns></returns>
        internal string GetMidPKSQL(FyPrimaryKeyAttribute fyPrimaryKey);

        /// <summary>
        /// 插入数据到数据库时，后置主键获取SQL
        /// </summary>
        /// <param name="fyPrimaryKey"></param>
        /// <returns></returns>
        internal string GetPostPKSQL(FyPrimaryKeyAttribute fyPrimaryKey);

        /// <summary>
        /// 字段类型为json的字段转值，比如对于Postgresql数据库，将传入的object对应序列化为json字符串返回
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        internal string ConvertDbJsonValue(object value);

        /// <summary>
        /// 将SQL语句转换为只查一条的语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        internal string ToSingleSQL(string sql);

        /// <summary>
        /// 将SQL转换为分页查询语句
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pageNumber"></param>
        /// <param name="perPage"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        internal string ToPgQuerySQL(string sql, int pageNumber, int perPage, string orderBy);

        /// <summary>
        /// 生成“当指定字段值为NULL时，用XX值替代的SQL语句”
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        internal string GenNvlSQL(string fieldName, object[] values);
    }
}
